<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="供应商名称" prop="suppliername">
        <el-input
          v-model="queryParams.suppliername"
          placeholder="请输入所在供应商名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所在仓库" prop="warehousename">
        <el-input
          v-model="queryParams.warehousename"
          placeholder="请输入所在仓库"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车辆品牌" prop="brand">
        <el-input
          v-model="queryParams.brand"
          placeholder="请输入车辆品牌"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车辆类型" prop="model">
        <el-input
          v-model="queryParams.model"
          placeholder="请输入车辆类型"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车身颜色" prop="color">
        <el-input
          v-model="queryParams.color"
          placeholder="请输入车身颜色"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="发动机号" prop="enginenumber">
        <el-input
          v-model="queryParams.enginenumber"
          placeholder="请输入发动机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车架号" prop="vin">
        <el-input
          v-model="queryParams.vin"
          placeholder="请输入车架号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="售价" prop="price">
        <el-input
          v-model="queryParams.price"
          placeholder="请输入售价"
          clearable
          @keyup.enter.native="handleQuery"
          oninput="value=value.replace(/[^\d.]/g,'')"
          @click.native="open2"

        />
      </el-form-item>
      <el-form-item label="核载人数" prop="seatingcapacity">
        <el-input
          v-model="queryParams.seatingcapacity"
          placeholder="请输入核载人数"
          clearable
          @keyup.enter.native="handleQuery"
           oninput="value=value.replace(/[^\d.]/g,'')"
            @click.native="open2"
        />
      </el-form-item>
      <el-form-item label="发动机类型" prop="enginetype">
        <el-input
          v-model="queryParams.enginetype"
          placeholder="请输入发动机类型"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="排量" prop="enginedisplacement">
        <el-input
          v-model="queryParams.enginedisplacement"
          placeholder="请输入排量"
          clearable
          @keyup.enter.native="handleQuery"
           oninput="value=value.replace(/[^\d.]/g,'')"
            @click.native="open2"
        />
      </el-form-item>
      <el-form-item label="功率" prop="power">
        <el-input
          v-model="queryParams.power"
          placeholder="请输入功率"
          clearable
          @keyup.enter.native="handleQuery"
           oninput="value=value.replace(/[^\d.]/g,'')"
            @click.native="open2"
           
        />
      </el-form-item>
      <el-form-item label="车轴数量" prop="axlesnumber">
        <el-input
          v-model="queryParams.axlesnumber"
          placeholder="请输入车轴数量"
          clearable
          @keyup.enter.native="handleQuery"
           oninput="value=value.replace(/[^\d.]/g,'')"
            @click.native="open2"
        />
      </el-form-item>
      <el-form-item label="车轴距离" prop="wheelbase">
        <el-input
          v-model="queryParams.wheelbase"
          placeholder="请输入车轴距离"
          clearable
          @keyup.enter.native="handleQuery"
           oninput="value=value.replace(/[^\d.]/g,'')"
            @click.native="open2"
        />
      </el-form-item>
      <el-form-item label="前轮距" prop="fronttrack">
        <el-input
          v-model="queryParams.fronttrack"
          placeholder="请输入前轮距"
          clearable
          @keyup.enter.native="handleQuery"
           oninput="value=value.replace(/[^\d.]/g,'')"
            @click.native="open2"
        />
      </el-form-item>
      <el-form-item label="后轮距" prop="reartrack">
        <el-input
          v-model="queryParams.reartrack"
          placeholder="请输入后轮距"
          clearable
          @keyup.enter.native="handleQuery"
           oninput="value=value.replace(/[^\d.]/g,'')"
            @click.native="open2"
        />
      </el-form-item>
      <el-form-item label="满载总质量" prop="grossvichcleweight">
        <el-input
          v-model="queryParams.grossvichcleweight"
          placeholder="请输入满载总质量"
          clearable
          @keyup.enter.native="handleQuery"
           oninput="value=value.replace(/[^\d.]/g,'')"
            @click.native="open2"
        />
      </el-form-item>
      <el-form-item label="汽车整备质量" prop="curbweight">
        <el-input
          v-model="queryParams.curbweight"
          placeholder="请输入汽车整备质量"
          clearable
          @keyup.enter.native="handleQuery"
           oninput="value=value.replace(/[^\d.]/g,'')"
            @click.native="open2"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

 <!--   <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['vehiclesell:vehiclesell:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['vehiclesell:vehiclesell:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['vehiclesell:vehiclesell:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['vehiclesell:vehiclesell:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
 -->
    <el-table v-loading="loading" :data="vehiclesellList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column type="expand">
              <template slot-scope="scope" >
               <el-tag style="font-size: 13px;" >发动机号：{{scope.row.enginenumber}}</el-tag> ||
                <el-tag style="font-size: 13px;">功率：{{scope.row.power}}</el-tag> ||
                <el-tag style="font-size: 13px;">车轴数量：{{scope.row.axlesnumber}}</el-tag> ||
                <el-tag style="font-size: 13px;">车轴距离：{{scope.row.wheelbase}}</el-tag> ||
                <el-tag style="font-size: 13px;">前轮距：{{scope.row.fronttrack}}</el-tag> ||
                <el-tag style="font-size: 13px;">后轮距：{{scope.row.reartrack}}</el-tag> <br><br>
                <el-tag style="font-size: 13px;">满载总质量：{{scope.row.grossvichcleweight}}</el-tag> ||
                <el-tag style="font-size: 13px;">汽车整备质量：{{scope.row.curbweight}}</el-tag> ||
                <el-tag style="font-size: 13px;">生产日期：{{scope.row.manufacturedate}}</el-tag> ||
                 <el-tag style="font-size: 13px;">车架号：{{scope.row.vin}}</el-tag> ||
                  <el-tag style="font-size: 13px;">排量：{{scope.row.enginedisplacement}}</el-tag>
              </template>
            </el-table-column >
      <el-table-column label="车辆品牌" align="center" prop="brand" />
      <el-table-column label="车辆类型" align="center" prop="model" />
      <el-table-column label="车身颜色" align="center" prop="color" />
      <el-table-column label="核载人数" align="center" prop="seatingcapacity" />
      <el-table-column label="发动机类型" align="center" prop="enginetype" />
      <el-table-column label="供应商名称" align="center" prop="suppliername" />
      <el-table-column label="所在仓库" align="center" prop="warehousename" />
       <el-table-column label="售价" align="center" prop="price" />

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="medium"
            type="text"
            icon="el-icon-shopping-cart-2"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['vehiclesell:vehiclesell:edit']"
          >购买</el-button>
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['vehiclesell:vehiclesell:remove']"
          >删除</el-button> -->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改车辆销售对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
       <el-form-item label="客户ID" prop="customerid">
         <el-select v-model="form.customerid" placeholder="请选择客户ID" filterable clearable>
         	<el-option
         	v-for="(item,index) in customerList"
         	:key="item.index"
         	:label="item.custormerid"
         	:value="item.custormerid">
         	</el-option>
         </el-select>
       </el-form-item>
        <el-form-item label="销售员ID" prop="salespersonid">
         <!-- <el-input v-model="form.salespersonid" placeholder="请输入销售员ID" > -->
          <el-select v-model="form.salespersonid" placeholder="请选择" filterable clearable>
            <el-option
                v-for="(item,index) in salespersonoptions"
                :key="item.index"
                :label="item.salespersonid"
                :value="item.salespersonid">
              </el-option>
            </el-select>
<!--          </el-input>-->
        </el-form-item>
        <el-form-item label="联系方式" prop="contactnumber">
          <el-input v-model="form.contactnumber" placeholder="请输入联系方式" />
        </el-form-item>
        <el-form-item label="收货地址" prop="address" >
          <el-input v-model="form.address" type="textarea"  placeholder="请输入收货地址" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>

</template>

<script>
import { listVehiclesell, getVehiclesell, delVehiclesell, addVehiclesell, updateVehiclesell } from "@/api/vehiclesell/vehiclesell";
import { getSalespersons } from "@/api/salesperson/salesperson";
import { getcustomersList } from "@/api/customer/customer";

export default {
  name: "Vehiclesell",
  data() {
    return {
      customerList:[],
      salespersonoptions:[],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 车辆销售表格数据
      vehiclesellList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        supplierid: null,
        warehouseid: null,
        brand: null,
        model: null,
        color: null,
        enginenumber: null,
        vin: null,
        price: null,
        seatingcapacity: null,
        enginetype: null,
        enginedisplacement: null,
        power: null,
        axlesnumber: null,
        wheelbase: null,
        fronttrack: null,
        reartrack: null,
        grossvichcleweight: null,
        curbweight: null,
        suppliername:null,
        warehousename:null,
         address:null,
          contactnumber:null,
          salespersonname:null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        customerid: [
          { required: true, message: "客户ID不能为空", trigger: "blur" }
        ],
        salespersonid: [
          { required: true, message: "销售员ID不能为空", trigger: "blur" }
        ],
        contactnumber: [
          { required: true, message: "联系方式不能为空", trigger: "blur" }
        ],
        address: [
          { required: true, message: "收货地址不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
    this.getListSalespersons();
    this.customersList();
      },
  methods: {
     open2() {
            this.$message({
              message: '请输入数字',
              type: 'success'
            });
          },
    customersList(){
      getcustomersList().then(response=>{
        this.customerList=response.data;
        console.info(response.data);
      })
    },
    getListSalespersons(){
      getSalespersons().then(response=>{
        this.salespersonoptions=response.data;
      })
    },
    /** 查询车辆销售列表 */
    getList() {
      this.loading = true;
      listVehiclesell(this.queryParams).then(response => {
        this.vehiclesellList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        vehicleid: null,
        status: null,
        supplierid: null,
        warehouseid: null,
        customerid: null,
        salespersonid: null,
        brand: null,
        model: null,
        color: null,
        manufacturedate: null,
        enginenumber: null,
        vin: null,
        primeprice: null,
        price: null,
        createtime: null,
        modifytime: null,
        deleted: null,
        seatingcapacity: null,
        enginetype: null,
        enginedisplacement: null,
        power: null,
        axlesnumber: null,
        wheelbase: null,
        fronttrack: null,
        reartrack: null,
        grossvichcleweight: null,
        curbweight: null,
        suppliername:null,
        warehousename:null,
         address:null,
          contactnumber:null,
          salespersonname:null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.vehicleid)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加车辆销售";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const vehicleid = row.vehicleid
      getVehiclesell(vehicleid).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "车辆销售";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.vehicleid != null) {
            updateVehiclesell(this.form).then(response => {
              this.$modal.msgSuccess("购买成功");
              this.open = false;
              this.getList();
            });
          } else {
            addVehiclesell(this.form).then(response => {
              this.$modal.msgSuccess("购买成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const vehicleids = row.vehicleid || this.ids;
      this.$modal.confirm('是否确认删除车辆销售编号为"' + vehicleids + '"的数据项？').then(function() {
        return delVehiclesell(vehicleids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('vehiclesell/vehiclesell/export', {
        ...this.queryParams
      }, `vehiclesell_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>

<style>
  .demo-table-expand {
    font-size: 0;
  }
  .demo-table-expand label {
    width: 100px;
    color: #515a6e;
  }
  .demo-table-expand .el-form-item {
    margin-left: 65px;
    margin-right: 0;
    margin-bottom: 0;
    width: 100%;
  }
</style>
